class Solution(object):
    def isValidBST(self, root):
        """
        :type root: TreeNode
        :rtype: bool
        """
        #先序遍历
        def DFS(root, lower, upper):
            #空节点
            if root is None:
                return True
            
            if root.val <= lower or root.val >= upper:
                return False

            return DFS(root.left, lower, root.val) and DFS(root.right, root.val, upper)

        return DFS(root, float("-inf"), float("inf"))
